<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Validator;
class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
        //
        //\Carbon\Carbon::setLocale('zh');

        //注册人机验证规则
        Validator::extendImplicit('luotest_response', function($attribute, $value, $parameters) {
            //return $value == 'foo';
            if(empty($value)){
                return false;
            }
            $response = \Guzzle::post(
                'https://captcha.luosimao.com/api/site_verify',
                [
                    'form_params' => [
                        //'api_key' => 'f6b0ecc20a370a991a223117124bdd89',
                        'api_key' => '1e4e32d46647804d20c07dd48da3cebf',
                        'response'=>$value

                    ]
                ]
            );
            //dd($response->getBody()->getContents());
            //return false;
            $response=json_decode($response->getBody()->getContents());
            //dd($response);
            if($response->res=='success'){
                return true;
            }else{
                return false;
            }

        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
